﻿using MiniFox.Caching;
using MiniFox.Components;
using MiniFox.Data;
using MiniFox.Infrastructure;
using MiniFox.Platform.Applications.Auth;
using MiniFox.Platform.Applications.Providers;
using MiniFox.Platform.Applications.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MiniFox.Platform.Applications
{
    /// <summary>
    /// 管理服务
    /// </summary>
    public class AdministrationService : ApiServiceBase, IAdministrationService
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="principal"></param>
        public AdministrationService(SystemPrincipal principal) : base(principal)
        {
            if (!this.Principal.IsAdministrator)
                throw new MiniFox.Exceptions.SystemException(Resources.ResMessage.MSG_FunctionOnlyForAdmin);
        }
        /// <summary>
        /// 
        /// </summary>
        [AutoWired]
        protected IAdministrationProvider Provider { get; set; }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="envConfig"></param>
        public void SetEnvironmentConfig(EnvConfig envConfig)
        {
            this.Provider.SetEnvironmentConfig(envConfig);
            CacheService.RemoveObject(PlatformService.ENV_CONFIG_KEY);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public EnvConfig GetEnvironmentConfig()
        {
            return this.Provider.GetEnvironmentConfig();
        }
        //#region 模块管理
        ///// <summary>
        ///// 
        ///// </summary>
        ///// <param name="queryObject"></param>
        ///// <returns></returns>
        //public ResultObject<ViewTable> QuerySystemModules(PagedQueryObject queryObject)
        //{
        //    var result = this.Provider.GetSystemModules(queryObject);
        //    return result;
        //}
        ///// <summary>
        ///// 
        ///// </summary>
        ///// <param name="module"></param>
        //public void SaveSystemModule(SystemNavModule module)
        //{
        //    this.Provider.SaveSystemModule(module);
        //}
        ///// <summary>
        ///// 
        ///// </summary>
        ///// <param name="moduleId"></param>
        //public void RemoveSystemModule(string moduleId)
        //{
        //    this.Provider.RemoveSystemModule(moduleId);
        //}
        //#endregion

        //#region 应用管理
        ///// <summary>
        ///// 
        ///// </summary>
        ///// <param name="queryObject"></param>
        ///// <returns></returns>
        //public ResultObject<ViewTable> QuerySystemApps(PagedQueryObject queryObject)
        //{
        //    var result = this.Provider.GetSystemApps(queryObject);
        //    return result;
        //}
        ///// <summary>
        ///// 
        ///// </summary>
        ///// <param name="app"></param>
        //public void SaveSystemApp(SystemApp app)
        //{
        //    this.Provider.SaveSystemApp(app);
        //}
        ///// <summary>
        ///// 
        ///// </summary>
        ///// <param name="appId"></param>
        //public void RemoveSystemApp(string appId)
        //{
        //    this.Provider.RemoveSystemApp(appId);
        //}
        //#endregion

    }
}
